<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        window.onload=function(){
            function loadImg(src) {
                return new Promise((resolve, reject) => {
                    let img = document.createElement('img');
                    img.onload = function () {
                        resolve(img);
                    };
                    img.onerror = function (e) {
                        // 返回错误信息
                        reject("catch 错误 加载失败")
                    }
                    img.src = src;
                })
            }
            var src1 = '../../../../images/award1.jpg'; //180
            var src2 = '../../../../images/Logo.png';   //179
            var result1 = loadImg(src1);
            var result2 = loadImg(src2);
            
            // async/await 必须成对出现
            // await 后面跟的必须是一个Promise实例
            // 完全同步的写法 不用再像then中传入回调函数在返回结果
            var load=async function(){
                var r1=await result1;
                var r2=await result2;
                console.log(r1);
                console.log(r2);
            }
            load();
            console.log("测试是否我先打印");
        }
    </script>
</body>
</html>